package com.example.cinema.request;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.sax.ElementListener;
import android.util.Log;

import com.bumptech.glide.signature.ObjectKey;
import com.example.cinema.R;
import com.example.cinema.UserAttribute;
import com.example.cinema.bindingdata.Advert;
import com.example.cinema.bindingdata.CircleItemData;
import com.example.cinema.bindingdata.CommentShortData;
import com.example.cinema.bindingdata.FollowFansData;
import com.example.cinema.bindingdata.LiveItemData;
import com.example.cinema.bindingdata.LiveTypeData;
import com.example.cinema.bindingdata.PlayerData;
import com.example.cinema.bindingdata.ShortBindingData;
import com.example.cinema.bindingdata.UserItemViewData;
import com.example.cinema.bindingdata.UserWorksData;
import com.example.cinema.bindingdata.VideoData;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class RequestData {

    private String url;
    private String purl;

    public RequestData(Context context) {
        try {
            ApplicationInfo info = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            url = info.metaData.getString("url");
            purl = info.metaData.getString("playurl");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取视频评价
     *
     * @param vid 视频ID
     * @param p   页码
     * @param l   数量
     * @return
     */
    public List<CircleItemData> GetAppraise(String vid, int p, int l) {
        List<CircleItemData> circledata = new ArrayList<>();
        OkHttpClient client = new OkHttpClient();
        FormBody form = new FormBody.Builder().add("vid", vid)
                .add("page", String.valueOf(p)).add("limit", String.valueOf(l)).build();
        Request request = new Request.Builder().post(form).url(url + "/com/appraise").build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("III", bod);
            JSONObject JO = new JSONObject(bod);
            JSONArray array = JO.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                JSONObject object = array.getJSONObject(i);
                CircleItemData data = new CircleItemData();
                data.msgcontext.set(object.getString("usertext"));
                data.userimage.set( object.getString("userimg"));
                data.username.set(object.getString("username"));
                data.usertimes.set(object.getString("usertime"));
                data.zannumbes.set(object.getString("userlove"));
                data.usersid.set(object.getString("usersid"));
                circledata.add(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return circledata;
    }

    /**
     * 获取视频评价
     *
     * @param vid 视频ID
     * @param p   页码
     * @param l   数量
     * @return
     */
    public JSONObject GetCircleData(String vid, int p, int l) {
        JSONObject JO = null;
        OkHttpClient client = new OkHttpClient();
        FormBody form = new FormBody.Builder().add("vid", vid)
                .add("page", String.valueOf(p)).add("limit", String.valueOf(l)).build();
        Request request = new Request.Builder().post(form).url(url + "/com/appraise").build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("III", bod);
            JO = new JSONObject(bod);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return JO;
    }


    /**
     * 根据类型获取猜你喜欢
     *
     * @param tid 分类ID
     * @return
     */
    public List<VideoData> GetCai(String tid) {
        List<VideoData> videolist = new ArrayList<>();
        OkHttpClient client = new OkHttpClient();
        FormBody form = new FormBody.Builder().add("type", tid).add("page", "1").add("limit", "12").build();
        Request request = new Request.Builder().post(form).url(url + "/com/typevideo").build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("III", bod);
            JSONObject object = new JSONObject(bod);
            JSONArray array = object.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                JSONObject Jo = array.getJSONObject(i);
                VideoData videoData = new VideoData();
                String sid = Jo.getString("videosid");
                videoData.videosid.set(sid);
                Log.i("WWWW猜猜", sid);
                String nam = Jo.getString("videoname");
                videoData.videoname.set(nam);
                String tye = Jo.getString("videotype");
                videoData.videotype.set(tye);
                String tim = Jo.getString("videotime");
                Log.i("QQSDDED",tim);
                videoData.videotime.set(GetTimes(tim));
                String bif = Jo.getString("videobrief");
                videoData.videobrief.set(bif);
                String gif = Jo.getString("videogif");
                videoData.videogif.set(gif);
                String img = Jo.getString("videoimg");
                videoData.videothum.set(img);
                String tag = Jo.getString("videotag");
                videoData.videotage.set(tag);
                String cvr = Jo.getString("videocover");
                videoData.videoimge.set(cvr);
                String usr = Jo.getString("videouser");
                videoData.videouser.set(usr);
                String uid = Jo.getString("videousid");
                videoData.videousid.set(uid);
                String prt = Jo.getString("videopart");
                videoData.videopart.set(prt);
                String lve = Jo.getString("videolove");
                videoData.videolove.set(lve);
                String pth = Jo.getString("videopath");
                videoData.videourls.set(pth);
                videolist.add(videoData);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return videolist;
    }

    public String GetTimes(String time) {
        int tm = Integer.valueOf(time);
        int ss = tm / 60;
        return ss + "分钟";
    }

    /**
     * 短视频数据获取
     *
     * @param typeid 分类ID固定1024
     * @param p      页码
     * @param l      数量
     * @return
     */
    public List<ShortBindingData> GetShortVideo(String typeid, int p, int l) {
        List<ShortBindingData> data = new ArrayList<>();
        OkHttpClient client = new OkHttpClient();
        FormBody formBody = new FormBody.Builder().add("page", String.valueOf(p)).add("type", typeid).add("limit", String.valueOf(l)).build();
        Request request = new Request.Builder().url(url + "/com/typevideo").post(formBody).build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("HHH", bod);
            JSONObject object = new JSONObject(bod);
            JSONArray array = object.getJSONArray("data");

            for (int i = 0; i < array.length(); i++) {
                ShortBindingData shordata = new ShortBindingData();
                JSONObject jo = array.getJSONObject(i);
                shordata.image.set(jo.getString("videocover"));
                shordata.title.set(jo.getString("videoname"));
                shordata.playurl.set(jo.getString("videopart"));
                shordata.imgurl.set(jo.getString("videouimg"));
                shordata.texts.set(jo.getString("videobrief"));
                shordata.useruid.set(jo.getString("videousid"));
                shordata.videourl.set(jo.getString("videopath"));
                shordata.videoid.set(jo.getString("videosid"));
                shordata.lovenum.set(jo.getString("videolove"));
                shordata.centimg.set(jo.getString("videoimg"));
                data.add(shordata);
                Log.i("uuuu", "遍历数据");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return data;
    }

    /**
     * 获取短视频评语
     *
     * @param vid 视频ID
     * @param p   页码
     * @param l   数量
     * @return
     */
    public List<CommentShortData> GetShortComment(String vid, int p, int l) {
        List<CommentShortData> circledata = new ArrayList<>();
        OkHttpClient client = new OkHttpClient();
        FormBody form = new FormBody.Builder().add("vid", vid)
                .add("page", String.valueOf(p)).add("limit", String.valueOf(l)).build();
        Request request = new Request.Builder().post(form).url(url + "/com/appraise").build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("III", bod);
            JSONObject JO = new JSONObject(bod);
            JSONArray array = JO.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                JSONObject object = array.getJSONObject(i);
                CommentShortData data = new CommentShortData();
                data.comments.set(object.getString("usertext"));
                data.userimg.set(url + "/" + object.getString("userimg"));
                data.username.set(object.getString("username"));
                data.zannumbe.set(object.getString("userlove"));
                data.usersid.set(object.getString("usersid"));
                circledata.add(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return circledata;
    }

    /**
     * 获取用户作品
     *
     * @return
     */
    public List<UserWorksData> GetUserWorks(int p, int l, UserAttribute attribute) {
        List<UserWorksData> data = new ArrayList<>();
        OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
            @Override
            public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

            }

            @NotNull
            @Override
            public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                List<Cookie> cookies = new ArrayList<>();
                Cookie cookie = new Cookie.Builder()
                        .hostOnlyDomain(httpUrl.host())
                        .name("uid")
                        .path("/us/").value(attribute.getUID())
                        .build();
                Cookie cookie1 = new Cookie.Builder()
                        .hostOnlyDomain(httpUrl.host())
                        .name("token")
                        .path("/us/")
                        .value(attribute.getToken())
                        .build();
                cookies.add(cookie);
                cookies.add(cookie1);
                return cookies;
            }
        }).build();
        FormBody formBody = new FormBody.Builder().add("page", String.valueOf(p)).add("limit", String.valueOf(l)).build();
        Request request = new Request.Builder().url(url + "/us/usfilelist").post(formBody)
                .build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("AAABB", bod);
            JSONObject obj = new JSONObject(bod);
            JSONArray array = obj.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                UserWorksData worksData = new UserWorksData();
                JSONObject ob = array.getJSONObject(i);

                worksData.filestate.set(ob.getInt("videostate"));
                Log.i("UUU", ob.getString("videoimage"));
                if (ob.getString("videoimage").length() < 5) {
                    worksData.fileimage.set(null);
                } else {
                    worksData.fileimage.set(url + "/" + ob.getString("videoimage"));
                }
                worksData.filezan.set(ob.getString("videolove"));
                if (ob.getString("videoplayurl").length() < 5) {
                    worksData.fileurls.set(null);
                } else {
                    worksData.fileurls.set(purl + "/" + ob.getString("videoplayurl"));
                }

                data.add(worksData);
            }
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return data;
    }

    /**
     * 获取帖子列表
     *
     * @param p
     * @param l
     * @return
     */
    public List<UserItemViewData> GetMoodeData(int p, int l) {
        List<UserItemViewData> listdata = new ArrayList<>();
        OkHttpClient client = new OkHttpClient();
        FormBody formBody = new FormBody.Builder().add("page", p + "").add("limit", l + "").build();
        Request request = new Request.Builder().url(url + "/com/getmooddata").post(formBody).build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("HHH", bod);
            JSONArray array = new JSONArray(bod);
            for (int i = 0; i < array.length(); i++) {
                JSONObject object = array.getJSONObject(i);
                UserItemViewData itemViewData = new UserItemViewData();
                if(!object.isNull("moodpath"))
                {
                    itemViewData.gifpath.set(object.getString("moodpath"));
                }

                itemViewData.admire.set(object.getString("moodcom"));
                itemViewData.circleid.set(object.getString("moodmid"));
                String[] imglist = object.getString("moodimglist").split(",");
                Log.i("HHH", imglist.length + "数量");
                for (int h = 0; h < imglist.length; h++) {
                    imglist[h] = imglist[h];
                }
                itemViewData.contenimg.set(Arrays.asList(imglist));
                itemViewData.evaluate.set(object.getString("moodcom"));
                itemViewData.money.set(object.getString("moneys"));

                itemViewData.userid.set(object.getString("useruid"));
                itemViewData.userimage.set(object.getString("userimg"));
                itemViewData.usertitle.set(object.getString("moodtitle"));
                itemViewData.usertime.set(object.getString("moodtime"));
                itemViewData.username.set(object.getString("username"));
                itemViewData.usermsg.set(object.getString("moodconten"));
                listdata.add(itemViewData);
            }
            Log.i("HHH", "数量值"+listdata.size());
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return listdata;
    }

    /**
     * 获取帖子评价
     *
     * @param p
     * @param l
     * @param mid
     * @return
     */
    public JSONArray getMoodPingJia(int p, int l, String mid) {
        JSONArray array = null;
        OkHttpClient client = new OkHttpClient();
        FormBody formBody = new FormBody.Builder()
                .add("page", p + "").add("limit", l + "")
                .add("mid", mid)
                .build();
        Request request = new Request.Builder().url(url + "/com/getmoodassess").post(formBody).build();
        try {
            Response response = client.newCall(request).execute();
            array = new JSONArray(response.body().string());
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return array;
    }


    /**
     * 获取完整播放链接
     *
     * @param id
     * @return
     */
    public String GetVipUrl(String id, UserAttribute attribute) {
        String urls = null;
        OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
            @Override
            public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

            }

            @NotNull
            @Override
            public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                List<Cookie> ck = new ArrayList<>();
                Cookie cookiea = new Cookie.Builder()
                        .hostOnlyDomain(httpUrl.host())
                        .name("token")
                        .value(attribute.getToken())
                        .build();
                Cookie cookieb = new Cookie.Builder()
                        .hostOnlyDomain(httpUrl.host())
                        .name("uid")
                        .value(attribute.getUID())
                        .build();
                ck.add(cookiea);
                ck.add(cookieb);
                return ck;
            }
        }).build();
        FormBody formBody = new FormBody.Builder().add("vid", id).add("uid", attribute.getUID()).build();
        Request request = new Request.Builder().url(url + "/us/plyvidurl").post(formBody).build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("JJJDD",bod);
            JSONObject jsonObject = new JSONObject(bod);
            JSONObject data = jsonObject.getJSONObject("data");
            urls = data.getString("videopath");
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return urls;
    }


    public PlayerData GetUrlData(String vid, UserAttribute attribute) {
        PlayerData playerData = new PlayerData();
        OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
            @Override
            public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

            }

            @NotNull
            @Override
            public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                List<Cookie> list = new ArrayList<>();
                Cookie cookiea = new Cookie.Builder()
                        .name("token").value(attribute.getToken())
                        .name("uid").value(attribute.getUID())
                        .hostOnlyDomain(httpUrl.host())
                        .build();
                Cookie cookieb = new Cookie.Builder()
                        .name("token").value(attribute.getToken())
                        .name("uid").value(attribute.getUID())
                        .hostOnlyDomain(httpUrl.host())
                        .build();
                list.add(cookiea);
                list.add(cookieb);
                return list;
            }
        }).build();
        FormBody formBody = new FormBody.Builder().add("vid", vid).build();
        Request request = new Request.Builder().post(formBody).url(url + "/us/getviddata").build();
        try {
            Response response = client.newCall(request).execute();
            JSONObject jo = new JSONObject(response.body().string());
            playerData.userimg.set(jo.getString("videouimg"));
            playerData.videolove.set(jo.getString("videolove"));
            playerData.playerurl.set(jo.getString("videopath"));
            playerData.videobrief.set(jo.getString("videobrief"));
            playerData.titles.set(jo.getString("videoname"));
            playerData.videouptime.set(jo.getString("videouptime"));
            playerData.videouser.set(jo.getString("videouser"));
            playerData.videotype.set(jo.getString("videotype"));
            playerData.videovid.set(jo.getString("videosid"));
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return playerData;
    }


    /**
     * 搜索影片
     *
     * @param text
     * @param pag
     * @param limit
     * @return
     */
    private MediaType FORM_CONTENT_TYPE = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");

    public List<VideoData> SerchData(String text, int pag, int limit, UserAttribute attribute) {
        List<VideoData> data = new ArrayList<>();
        OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
            @Override
            public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

            }

            @NotNull
            @Override
            public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                List<Cookie> list = new ArrayList<>();
                Cookie cookiea = new Cookie.Builder()
                        .hostOnlyDomain(httpUrl.host())
                        .name("token").value(attribute.getToken())
                        .build();
                Cookie cookieb = new Cookie.Builder()
                        .hostOnlyDomain(httpUrl.host())
                        .name("uid").value(attribute.getUID())
                        .build();
                list.add(cookiea);
                list.add(cookieb);
                return list;
            }
        }).build();
        String param = "key=" + text + "&page=" + pag + "&limit=" + limit;
        RequestBody requestBody = RequestBody.create(FORM_CONTENT_TYPE, param);
        Request request = new Request.Builder().url(url + "/us/search").post(requestBody).build();
        try {
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("UUUU", bod);
            JSONObject object = new JSONObject(bod);
            JSONArray array = object.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                VideoData videoData = new VideoData();
                JSONObject Jo = array.getJSONObject(i);
                videoData.videolove.set(Jo.getString("videolove"));
                videoData.videoname.set(Jo.getString("videoname"));
                videoData.videotype.set(Jo.getString("videotype"));
                videoData.videotime.set(Jo.getString("videotime"));
                videoData.videobrief.set(Jo.getString("videobrief"));
                videoData.videogif.set(Jo.getString("videogif"));
                Log.i("UUUU", videoData.videogif.get());
                videoData.videoimge.set(Jo.getString("videoimg"));
                Log.i("UUUU", videoData.videoimge.get());
                videoData.videotage.set(Jo.getString("videotag"));
                videoData.videouser.set(Jo.getString("videouser"));
                videoData.videopart.set(Jo.getString("videopart"));
                Log.i("UUUU", videoData.videopart.get());
                videoData.videousid.set(Jo.getString("videousid"));
                videoData.videourls.set(Jo.getString("videopath"));
                Log.i("UUUU", videoData.videourls.get());
                videoData.videouimg.set(Jo.getString("videouimg"));
                Log.i("UUUU", videoData.videouimg.get());
                videoData.videouptime.set(Jo.getString("videouptime"));
                videoData.videosid.set(Jo.getString("videosid"));
                data.add(videoData);
            }
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return data;
    }


    /**
     * 获取直播数据
     *
     * @param page
     * @param limit
     * @param attribute
     * @return
     */
    public List<LiveItemData> GetLivePageData(int page, int limit, UserAttribute attribute) {
        List<LiveItemData> data = new ArrayList<>();
        try {
            OkHttpClient client = new OkHttpClient.Builder()
                    .cookieJar(new CookieJar() {
                        @Override
                        public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

                        }

                        @NotNull
                        @Override
                        public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                            List<Cookie> list = new ArrayList<>();
                            Cookie cookiea = new Cookie.Builder()
                                    .name("token").value(attribute.getToken())
                                    .hostOnlyDomain(httpUrl.host())
                                    .build();
                            Cookie cookieb = new Cookie.Builder()
                                    .name("uid").value(attribute.getUID())
                                    .hostOnlyDomain(httpUrl.host())
                                    .build();
                            list.add(cookiea);
                            list.add(cookieb);
                            return list;
                        }
                    })
                    .build();
            FormBody formBody = new FormBody.Builder()
                    .add("page", String.valueOf(page))
                    .add("limit", String.valueOf(limit))
                    .build();
            Request request = new Request.Builder().post(formBody).url(url + "/com/relive").build();
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("UUU", bod);
            if (bod != null) {
                JSONObject jo = new JSONObject(bod);
                JSONArray array = jo.getJSONArray("data");
                for (int i = 0; i < array.length(); i++) {
                    LiveItemData itemData = new LiveItemData();
                    JSONObject jsonObject = array.getJSONObject(i);
                    itemData.title.set(jsonObject.getString("livename"));
                    itemData.image.set(jsonObject.getString("livecover"));
                    itemData.plaurl.set(jsonObject.getString("livepath"));
                    itemData.relay.set(jsonObject.getString("liverelay"));
                    data.add(itemData);
                }

            }
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return data;
    }


    /**
     * 获取关注作者视频列表或者粉丝视频列表
     *
     * @param page      页码
     * @param limit     数量
     * @param attribute
     * @return
     */
    public List<FollowFansData> GetFollowFansData(int page, int limit, UserAttribute attribute, int type) {
        List<FollowFansData> followFansData = new ArrayList<>();
        try {
            OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
                @Override
                public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

                }

                @NotNull
                @Override
                public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                    List<Cookie> list = new ArrayList<>();
                    Cookie cookiea = new Cookie.Builder()
                            .hostOnlyDomain(httpUrl.host())
                            .name("token").value(attribute.getToken())
                            .build();
                    Cookie cookieb = new Cookie.Builder()
                            .hostOnlyDomain(httpUrl.host())
                            .name("uid").value(attribute.getUID())
                            .build();
                    list.add(cookiea);
                    list.add(cookieb);
                    return list;
                }
            }).build();
            FormBody formBody = new FormBody.Builder().add("page", page + "").add("limit", limit + "").add("uid", attribute.getUID()).build();
            Request request = null;
            if (type == 1) {
                request = new Request.Builder().post(formBody).url(url + "/us/followus").build();
                Log.i("GGDGH", "/us/followus");
            } else {
                request = new Request.Builder().post(formBody).url(url + "/us/fanslist").build();
                Log.i("GGDGH", "/us/fanslist?" + "page=" + page + "&limit=" + limit + "&uid=" + attribute.getUID());
            }
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            JSONObject jo = new JSONObject(bod);
            JSONArray array = jo.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                JSONObject object = array.getJSONObject(i);
                FollowFansData fansData = new FollowFansData();
                fansData.image.set(object.getString("image"));
                Log.i("MMMM", fansData.image.get());
                fansData.uimge.set(object.getString("uimge"));
                Log.i("MMMM", fansData.uimge.get());
                fansData.userm.set(object.getString("userm"));
                fansData.playurl.set(object.getString("playurl"));
                fansData.shorturl.set(object.getString("shorturl"));
                fansData.videoid.set(object.getString("videoid"));
                followFansData.add(fansData);
            }
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return followFansData;
    }


    /**
     * 获取直播分类
     *
     * @return
     */
    public List<LiveTypeData> ReqLiveData() {
        List<LiveTypeData> livetypes = new ArrayList<>();
        try {
            OkHttpClient client = new OkHttpClient.Builder().build();
            Request request = new Request.Builder().url(url + "/com/livetypes").get().build();
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("HHHDD",bod);
            JSONObject jo = new JSONObject(bod);
            JSONArray array = jo.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                JSONObject AJO = array.getJSONObject(i);
                LiveTypeData typeData = new LiveTypeData();
                typeData.typename.set(AJO.getString("livetypename"));
                typeData.typetid.set(AJO.getString("livetypeid"));
                typeData.typeicon.set(AJO.getString("livetypeicon"));
                livetypes.add(typeData);
            }
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return livetypes;
    }

    /**
     * 根据分类获取直播分类分页数据
     *
     * @param page
     * @param limit
     * @param attribute
     * @param typeid
     * @return
     */
    public List<LiveItemData> GetLiveTypePageData(int page, int limit, UserAttribute attribute, String typeid) {
        List<LiveItemData> itemData = new ArrayList<>();
        try {
            OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
                @Override
                public void saveFromResponse(@NotNull HttpUrl httpUrl, @NotNull List<Cookie> list) {

                }

                @NotNull
                @Override
                public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
                    List<Cookie> list = new ArrayList<>();
                    Cookie cookiea = new Cookie.Builder()
                            .hostOnlyDomain(httpUrl.host())
                            .name("token").value(attribute.getToken())
                            .build();
                    Cookie cookieb = new Cookie.Builder()
                            .hostOnlyDomain(httpUrl.host())
                            .name("uid").value(attribute.getUID())
                            .build();
                    list.add(cookiea);
                    list.add(cookieb);
                    return list;
                }
            }).build();
            FormBody formBody = new FormBody.Builder().add("pag", page + "").add("limit", limit + "").add("tid", typeid).build();
            Request request = new Request.Builder().post(formBody).url(url + "/com/typeslive").build();
            Response response = client.newCall(request).execute();
            String bod = response.body().string();
            Log.i("KKKD", bod);
            JSONObject ob = new JSONObject(bod);
            JSONArray array = ob.getJSONArray("data");
            for (int i = 0; i < array.length(); i++) {
                JSONObject object = array.getJSONObject(i);
                LiveItemData data = new LiveItemData();
                data.relay.set(object.getString("liverelay"));
                data.plaurl.set(object.getString("livepath"));
                data.image.set(object.getString("livecover"));
                data.title.set(object.getString("livetext"));
                data.livename.set(object.getString("livename"));
                itemData.add(data);
            }

        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return itemData;
    }

    //获取APP下载地址
    public void Getdownload(UserAttribute attribute) {
        try {/**/
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(url + "/com/downloadurl").build();
            Response response = client.newCall(request).execute();
            String bod  = response.body().string();
            attribute.setDowurl(bod);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //获取客服QQ
    public void GetQQ(UserAttribute attribute)
    {
        try {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(url + "/com/getqqtext").get().build();
            Response response = client.newCall(request).execute();
            if(response.code()==200)
            {
                String bod = response.body().string();
                attribute.setQQtext(bod);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
